package day02;

import java.util.Scanner;

/**
 * Created by MGL on 2017/4/3.
 */
public class Test03 {
    //    int C1[MAX],C2[MAX],b[MAX];
//    int num[N];
//    long long total[N],ans;
    int[] C1 = new int[1000010];
    int[] C2 = new int[1000010];
    int[] b = new int[1000010];
    int[] num = new int[1000010];
    long[] total = new long[1000010];
    long ans;

    int lowbit(int x) {
        return x & (-x);
    }

    void add(int pos, int num, int[] C) {
        while (pos <= 1000010) {
            C[pos] += num;
            pos += lowbit(pos);
        }
    }

    int Sum(int pos, int[] C) {
        int sum = 0;
        while (pos > 0) {
            sum += C[pos];
            pos -= lowbit(pos);
        }
        return sum;
    }

    public static void main(String[] args) {
        Test03 test03 = new Test03();
        test03.test();
    }

    void init() {
        total[0] = 0;
        for (int i = 1; i <= 100010; i++) {
            total[i] = total[i - 1] + i;
        }
    }

    public void test() {
        init();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            num[i] = sc.nextInt();
            add(num[i] + 1, 1, C1);
            b[i] = i - Sum(num[i], C1);
            b[i] = b[i] - (Sum(num[i] + 1, C1) - Sum(num[i], C1) - 1);
        }
        for (int i = n - 1; i >= 0; i--) {
            add(num[i] + 1, 1, C2);
            b[i] = b[i] + Sum(num[i], C2);

        }
        ans = 0;
        for (int i = 0; i < n; i++) {
            ans += total[b[i]];
        }
        System.out.println(ans);

    }

}
